/*
 * @lc app=leetcode.cn id=345 lang=csharp
 *
 * [345] 反转字符串中的元音字母
 */

// @lc code=start
public class Solution {
    HashSet<char> chars = new HashSet<char>(){'a','e','i','o','u','A','E','I','O','U'};
    public string ReverseVowels(string s) 
    {
        var array = s.ToCharArray();
        char temp;
        int left = 0;
        int right = array.Length - 1;
        
        for(;left <= right; ++left)
        {
            var cl = array[left];
            if(!chars.Contains(cl))
            {
                continue;
            }
            
            while(left <= right && !chars.Contains(array[right]))
                --right;
                
            if(left <= right)
            {
                temp = cl;
                array[left] = array[right];
                array[right] = cl;
                --right;
            }
        }
        return new string(array);
    }
}
// @lc code=end

